﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Zeus.Infra.Cache
{
    public class MemoryCacheStorage : ICacheStorage
    {
        private int retrievedFromCacheCount = 0;
        private Dictionary<string, object> cacheStorage = new Dictionary<string, object>();

        public int RetrievedFromCacheCount()
        {
            return retrievedFromCacheCount;
        }

        public void Remove(string key)
        {
            throw new NotImplementedException();
        }

        public void Store(string key, object data)
        {
            if (cacheStorage.ContainsKey(key))
            {
                cacheStorage[key] = data;
            }
            else
            {
                cacheStorage.Add(key, data);
            }
        }

        public T Retrieve<T>(string key)
        {
            if (cacheStorage.ContainsKey(key))
            {
                retrievedFromCacheCount++;
                return (T)cacheStorage[key];
            }
            else
            {
                return default(T);
            }
        }  
    }
}
